package com.flyduck.security.config;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <p></p>
 *
 * @author flyduck 2021/7/5
 * @version V1.0
 * @modificationHistory=========================逻辑或功能性重大变更记录
 * @modify by user: flyduck 2021/7/5
 * @modify by reason:{方法名}:{原因}
 **/
@Configuration
public class AppConfig {

    @Bean
    public ObjectMapper objectMapper() {
        ObjectMapper mapper = new ObjectMapper();
        //配置在反序列化过程中如果json字符串中存在无法匹配的属性不会失败
        mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
        //配置禁用日期转换为Timestamp，序列化将调用StdDateFormat的format()方法，使用ISO-8601兼容格式"yyyy-MM-dd'T'HH:mm:ss.SSSZ"
        mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);

        //配置序列化禁用empty beans失败的配置
        mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);

        //在序列化时忽略值为 null 的属性
        //mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

        //忽略值为默认值的属性
        //mapper.setDefaultPropertyInclusion(Include.NON_DEFAULT);

        return mapper;
    }
}
